﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml.Linq;
using MindFusion.Diagramming;
using MindFusion.Drawing;
using Brush = System.Drawing.Brush;

namespace Skynet
{
    [Serializable]
    public class IconNode : DiagramNode
    {
        public bool MySelect;
        public int id;
        public Int32 Type;
        public StringFormat format;
        public Image icon;
        public string Label;
        public string ImagePath;
        public string word;
        public string domain;
        public string value;

        public IconNode(Diagram diagram, int type_, int id_)
            : base(diagram)
        {
            id = id_;
            Type = type_;
            ImagePath = Application.StartupPath;
            if (Type == 1)
            {
                Label = "ИВ";
                ImagePath += @"\Pic\blue.bmp";
            }
            if (Type == 2)
            {
                Label = "ПР";
                ImagePath += @"\Pic\green.bmp";
            }
            if (Type == 3)
            {
                
                ImagePath += @"\Pic\red.bmp";
            }
            icon = Image.FromFile(ImagePath);

            format = new StringFormat();
            format.Alignment = StringAlignment.Center;
            format.LineAlignment = StringAlignment.Center;
        }
        /// <summary>
        /// функция получения списка дуг к неименованным вершинам, возвращающая List<link>
        /// </summary>
        public List<DiagramLink> GetListToUnnamedNode()
        {
            var a = new List<DiagramLink>();
          
            for (int i = 0; i < OutgoingLinks.Count; i++)
            {
                if (((IconNode)OutgoingLinks[i].Destination).Type==2)
                {
                    a.Add(OutgoingLinks[i]);
                }
            }

            return a;
        }

        public override void Draw(IGraphics graphics, RenderOptions options)
        {

            Bounds = new RectangleF(Bounds.X, Bounds.Y, 5, 5);
            graphics.DrawImage(icon, Bounds.X, Bounds.Y);
            // Draw the label at the bottom
            var font = new Font("Arial", 2, FontStyle.Italic, GraphicsUnit.Pixel);
            format = new StringFormat();
            format.Alignment = StringAlignment.Center;
            format.LineAlignment = StringAlignment.Center;
            var labelBounds = new RectangleF(Bounds.X - 4, Bounds.Y + 5, 14, 5);
            graphics.DrawString(Label, font, Brushes.Black, labelBounds, format);

        }

        public override void DrawShadow(IGraphics graphics, RenderOptions options)
        {
            ImagePath = Application.StartupPath;
            ImagePath += @"\Pic\selected.bmp";

            var i = Image.FromFile(ImagePath);
            if (MySelect)
            {
                graphics.DrawImage(i , Bounds.X-1, Bounds.Y-1);
            }
        }
    }
    public class Value
    {
        public DataGridViewRow Row;
        public DataGridViewRow domainRow;
    }

    public class Domain
    {
        public DataGridViewRow Row;
    }

    public class Domains
    {
        public List<Domain> domList;
        public List<Value> valList;
        public Domains()
        {
            domList = new List<Domain>();
            valList = new List<Value>();
        }
    }
    public class Syn
    {
        public DataGridViewRow Row;
        public DataGridViewRow domainRow;
    }

    public class Word
    {
        public DataGridViewRow Row;
    }
    [Serializable]
    public class Words
    {
        public List<Word> wordList;
        public List<Syn> synList;
        public Words()
        {
            wordList = new List<Word>();
            synList = new List<Syn>();
        }
    }




    [Serializable]
    public class SerValue
    {
        public string value;
        public string domain;
    }
    [Serializable]
    public class SerDomain
    {
        public string domain;
    }
  
    [Serializable]
    public class SerSyn
    {
        public string syn;
        public string word;
    }
    [Serializable]
    public class SerWord
    {
        public string word;
    }
   

    [Serializable]
    public class SerIconNode
    {
        public RectangleF PointF;
        public Int32 id;
        public Int32 Type;
        public StringFormat format;
        public string Label;
        public string ImagePath;
        public string word;
        public string domain;
        public string value;
        public bool selected;
        public List<SerLink> outgoing = new List<SerLink>();
        public List<SerLink> incoming = new List<SerLink>();
       // public DiagramLinkCollection outgoing = new DiagramLinkCollection();
    //    public DiagramLinkCollection incoming = new DiagramLinkCollection();
    }
    [Serializable]
    public class SerLink
    {
        public int origin;
        public int destination;
        public string text;
    }
    [Serializable]
    public class KB
    {
        public List<SerIconNode> Nodes = new List<SerIconNode>();
        public List<SerLink> Links = new List<SerLink>();
        public List<SerDomain> Domains = new List<SerDomain>();
        public List<SerWord> Words = new List<SerWord>();
        public List<SerValue> Values = new List<SerValue>();
        public List<SerSyn> Syns = new List<SerSyn>();
    }

}